products = [['iphone', 6888], ['MacPro', 14800], ['小米6', 2499], ['Coffee', 31], ['Book', 60], ['Nike', 699]]
print('商品列表')
j = 0
for i in products:
    print(j, i[0], i[1])
    j = j + 1
buys = []
s = 0
while True:
    y = input('请输入您要购买的商品编号:')
    if y == 'q':
        print('您购买的商品：')
        for i in buys:
            print(i[0])
        for num in range(0, len(buys)):
            s = buys[num][1] + s
        print('需支付:', s)
        break
    elif int(y) > 5 or int(y) < 0:
        print('您输入的编号不存在，请重新输入:')
    else:
         buys.append(products[int(y)])


# 可以把输出优化下
